#pragma once

#include "driver/uart.h"

typedef struct dlt645_port_config{
	uart_port_t uart_num;
	int baud_rate;
    uart_word_length_t data_bits;       /*!< UART byte size*/
    uart_parity_t parity;               /*!< UART parity mode*/
    uart_stop_bits_t stop_bits;         /*!< UART stop bits*/
	uart_mode_t mode;
	int tx_io_num;
	int rx_io_num;
	int rts_io_num;
	int cts_io_num;
}dlt645_port_config_t;

//DLT645 环境结构体
typedef struct dlt645
{
    uint8_t addr[6];    //从机地址
    uint8_t debug;      //调试标志
    uint8_t uart_num;   //串口
    void * xSemaphore;
    bool (*sem_take)( struct dlt645 *ctx, int timeout);
	void (*sem_give)(struct dlt645 *ctx);
    int (*write)(struct dlt645 *ctx, uint8_t *buf, uint16_t len);     //底层写函数
    int (*read) (struct dlt645 *ctx, uint8_t *msg, uint16_t len);     //底层读函数
    void *port_data;                                            //移植层拓展接口
} dlt645_t;

//对外提供环境声明
// extern dlt645_t dlt645;
//645采集硬件层初始化
// int dlt645_port_init(dlt645_port_config_t *cfg);
int dlt645_port_create(dlt645_port_config_t *cfg, dlt645_t *dlt645);

// 645采集硬件层读数据
int dlt645_hw_read(dlt645_t *ctx, uint8_t *msg ,uint16_t len);
// 645采集硬件层写数据
int dlt645_hw_write(dlt645_t *ctx, uint8_t *buf, uint16_t len);
//645采集硬件层修改波特率
int dlt645_port_set_baudrate(struct dlt645 *ctx, int baudrate);
//645采集硬件层修改校验位
int dlt645_port_set_parity(struct dlt645 *ctx, int val);

